package com.qidian.mes.md.service.impl;

import com.qidian.mes.md.mapper.MaterialAndProductClassifyMapper;
import com.qidian.mes.md.service.MaterialAndProductClassifyService;
import com.qidian.mes.pojo.MaterialAndProductClassify;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-04-04 16:36
 **/
@Service
public class MaterialAndProductClassifyServiceImpl implements MaterialAndProductClassifyService {

    @Autowired
    private MaterialAndProductClassifyMapper materialAndProductClassifyMapper;
    @Override
    public QdResult<List<MaterialAndProductClassify>> findAll() {
        return QdResult.success(materialAndProductClassifyMapper.findAll());
    }

    @Override
    public QdResult updateClassifyName(String name, String id) {
        materialAndProductClassifyMapper.updateClassifyName(name,id);
        return QdResult.success();
    }

    @Override
    public QdResult deleteClassify(Integer id) {
        materialAndProductClassifyMapper.deleteClassify(id);
        return QdResult.success();
    }

    /**
     * @Author: CoolPro
     * @Date: 6/4/2024
     * @Description:
     * @Name: 添加分类信息
     * @param category 分类类型
     * @param name 名称
     * @return: com.qidian.mes.util.pojo.QdResult
    */
    @Override
    public QdResult addClassify(Integer category, String name) {
        List<MaterialAndProductClassify> categoryByName = materialAndProductClassifyMapper.findCategoryByName(name);
        if (categoryByName.size()>0){
            materialAndProductClassifyMapper.makeEnable(categoryByName.get(0).getIdClassify());
            return QdResult.success();
        }
        materialAndProductClassifyMapper.addClassify(name,category);
        return QdResult.success();
    }

    /**
     * @Author: CoolPro
     * @Date: 6/4/2024
     * @Description:  根据名称查询分类信息（精确查询）
     * @Name: queryClassifyByName
     * @param name
     * @return: com.qidian.mes.util.pojo.QdResult
    */

    @Override
    public QdResult queryClassifyByName(String name) {
        return QdResult.success(materialAndProductClassifyMapper.findCategoryByName(name));
    }


}
